package com.woniu.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.woniu.mapper.RoleMapper;
import com.woniu.pojo.DoctorRole;
import com.woniu.mapper.DoctorRoleMapper;
import com.woniu.pojo.Role;
import com.woniu.service.IDoctorRoleService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.woniu.vo.RoleVo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author doujiao
 * @since 2022-10-11
 */
@Service
public class DoctorRoleServiceImpl extends ServiceImpl<DoctorRoleMapper, DoctorRole> implements IDoctorRoleService {

    @Resource
    private DoctorRoleMapper doctorRoleMapper;
    @Resource
    private RoleMapper roleMapper;

    /**
     * 根据doctorId查询Role
     * @param doctorIdStr
     * @return
     */
    public Role queryRoleByDoctorId(String doctorIdStr) {
        int doctorId = Integer.parseInt(doctorIdStr);
        //构造查询对象
        QueryWrapper<DoctorRole> wrapper=new QueryWrapper<>();
        wrapper.eq("doctor_id",doctorId);
        //查询父doctorid的字段
        DoctorRole doctorRole = doctorRoleMapper.selectOne(wrapper);
        Long roleId = doctorRole.getRoleId();
        //根据roleid查询role
        Role role = roleMapper.selectById(roleId);
        return role;
    }
}
